/**
 * store的数据结构
 */
interface UserState {
    user: null | {
        id: number
        name: string
    }
    isAuthenticated: boolean
}

/**
 *  全局同步数据
 */
const state: UserState = {
    user: {
        id: null, // 用户id
        name: null // 用户name
    },
    isAuthenticated: false //是否登陆
}

/**
 * 同步操作
 */
const mutations = {
    SET_AUTH: (state: UserState, auth: boolean) => {
        state.isAuthenticated = auth
    }
}

/**
 * 异步操作
 */
const actions = {
    setAuth({ commit }, auth: boolean) {
        commit("SET_AUTH", auth)
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
